package com.lizi.core.java.util.map;

import java.util.Collections;
import java.util.Hashtable;
import java.util.Map;

public class HashMap {
    static final int MAXIMUM_CAPACITY = 1 << 30;
    
    public static void main(String[] args) {
		int a = tableSizeFor(128);
		System.out.println(a);
		Map<String, Object> hashTable = new Hashtable<>();
		
		Collections.synchronizedMap(hashTable);
	}
	
    /**
     * 00011001 1111 11 1 1
     *  0001100 1111 11 1 1
     *    00011 0011 11 1 1
     * @param cap
     * @return
     */
	static final int tableSizeFor(int cap) {
        int n = cap - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
    }
}



